package com.springcloud.consumercourse.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author
 * @create 2020-11-11 11:46
 */
@Configuration
public class HystrixDashboardConfiguration {

    @Bean
    public ServletRegistrationBean registrationBean(){
        HystrixMetricsStreamServlet metricsStreamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(metricsStreamServlet);
        //给Servlet设置属性
        servletRegistrationBean.setLoadOnStartup(1);  //是否在容器启动时创建servlet
        servletRegistrationBean.addUrlMappings("/hystrix.stream");     //设置servlet的映射地址,固定写法
        servletRegistrationBean.setName("HystrixMetricsStreamServlet");  //给servlet设置名字
        return servletRegistrationBean;
    }
}
